import java.util.Stack;

class Solution3 {
    public int calPoints(String[] operations) {
        Stack<Integer> stack = new Stack<>();
        Stack<Integer> stack2 = new Stack<>();
        int len = operations.length;
        for(int i = 0; i < len ; i++) {
            if (operations[i].charAt(0) == 'C') {
                stack.pop();
            } else if(operations[i].charAt(0) == 'D') {
                stack.push(stack.peek()*2);
            } else if(operations[i].charAt(0) == '+') {
                int a = stack.pop();
                int b = stack.peek();
                stack.push(a);
                stack.push(a+b);
            } else stack.push(Integer.parseInt(operations[i]));
        }
        int h = 0;
        while(!stack.empty()) {
            h = h + stack.pop();
        }
        return h;
    }
}
